package com.mouse.mapper;

import com.mouse.entity.DoubleAlleles;
import com.mouse.entity.GeneComposition;
import com.mouse.entity.GeneCompositionDoubleAlleles;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author godson
 * @since 2022-08-07
 */
public interface GeneCompositionDoubleAllelesMapper extends BaseMapper<GeneCompositionDoubleAlleles> {


    @Select("Select DISTINCT gcomda.* FROM (SELECT gcom.* FROM gene_category gca LEFT JOIN genecategory_genecomposition gg ON gca.gid=gg.gid LEFT JOIN gene_composition gcom ON gg.gcid=gcom.gcid WHERE gca.gid=#{gid}) gcom_result\n" +
            "LEFT JOIN gene_composition_double_alleles gcomda ON gcom_result.gcid=gcomda.gcid ")
    List<GeneCompositionDoubleAlleles> getGeneCompositionDoubleAllelesByGid(@Param("gid") Long gid);


    @Select("SELECT gcda.* FROM gene_composition gcom LEFT JOIN gene_composition_double_alleles gcda ON gcom.gcid=gcda.gcid WHERE gcom.gcid=#{gcid}")
    List<GeneCompositionDoubleAlleles> getGeneCompositionDoubleAllelesByGcid(@Param("gcid") Long gcid);

    /***
     * 3.2.1.1
     * @param did
     * @return
     */
    @Select("SELECT gcda.* FROM  double_alleles da LEFT JOIN gene_composition_double_alleles gcda ON da.did=gcda.did WHERE da.did=#{did}")
    List<GeneCompositionDoubleAlleles> getGeneCompositionDoubleAllelesByDid( @Param("did") Long did);


    @Select("SELECT DISTINCT gcda.* FROM gene_allele ga LEFT JOIN double_alleles_gene_allele daga ON ga.aid=daga.aid LEFT JOIN double_alleles da ON daga.did= da.did \n" +
            "LEFT JOIN gene_composition_double_alleles gcda ON gcda.did=da.did \n" +
            "WHERE daga.aid=#{aid}")
    List<GeneCompositionDoubleAlleles> getGCDAByAid(@Param("aid") Long aid);
}
